package com.example.wanbaqian.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.wanbaqian.R;
import com.example.wanbaqian.base.BaseActivity;
import com.example.wanbaqian.config.CommonValue;
import com.example.wanbaqian.base.HttpCallback;
import com.example.wanbaqian.config.HttpURL;
import com.example.wanbaqian.bean.BankInfo;
import com.example.wanbaqian.bean.Info;
import com.example.wanbaqian.utils.GetJsonUtils;
import com.example.wanbaqian.utils.HttpUtils;
import com.example.wanbaqian.utils.JsonUtils;
import com.example.wanbaqian.utils.SPUtils;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;

/**
 * 银行卡
 */
public class FindBankActivity extends BaseActivity {
    @BindView(R.id.tv_bankid)
    TextView tvBankid;
    @BindView(R.id.tv_bankname)
    TextView tvBankname;
    @BindView(R.id.tv_bank)
    TextView tvBank;
    @BindView(R.id.tv_tip)
    TextView tvTip;
    @BindView(R.id.rl_info)
    AutoRelativeLayout rlInfo;

    @Override
    protected int getLayout() {
        return R.layout.activity_findbank;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setStatusBarColor(R.color.main_color);
        setToolBar("银行卡管理");

        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        toolBar_tvRight.setVisibility(View.GONE);

        rlInfo.setVisibility(View.GONE);
        getDate();

    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void initDate() {
    }

    private void getDate() {
        HttpUtils.getInstance().post(GetJsonUtils.getInstance()
                        .getRequest(HttpURL.MY_BANK, mContext,
                                new String[]{"accessid"}
                                , new Object[]{SPUtils.getAccessid(mContext)})
                , HttpURL.MY_BANK, CommonValue.REQUEST_CODE1, new HttpCallback() {
                    @Override
                    public void onSuccess(String content, Info info, int requestCode) {
                        BankInfo bankInfo = JsonUtils.getInstance().jsonToObject(content, BankInfo.class);
                        if (bankInfo.getBank_id()==0) {
                            toolBar_tvRight.setText("添加");
                            rlInfo.setVisibility(View.GONE);

                            toolBar_tvRight.setVisibility(View.VISIBLE);
                            toolBar_tvRight.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    showToast("前往额度申请-实名认证");
//                                    openActivity(FindEdiBankActivity.class);
                                }
                            });
                        } else {
                            rlInfo.setVisibility(View.VISIBLE);
                            tvBank.setText(bankInfo.getBank_name());
                            tvBankid.setText("卡号:" + bankInfo.getBank_account());
                            tvBankname.setText("持卡人:" + bankInfo.getAcct_name());
                        }
                    }
                    @Override
                    public void onCacheSuccess(String content, Info info, int requestCode) {
                    }

                    @Override
                    public void onError(Info info, int requestCode) {
                        showToast(info.getMsg());
                    }
                });
    }
}
